package com.coreJava.shejimoshi.yuanxingmoshi;

import java.io.*;

/**
 * 作者: LCG
 * 日期: 2020/2/13 21:17
 * 描述:
 */
public class TestYuanXing implements Cloneable,Serializable {

    private String userName;

    private String password;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    //浅克隆
    public TestYuanXing clone() throws CloneNotSupportedException {
        return (TestYuanXing)super.clone();
    }

    //深克隆
    public TestYuanXing deepClone() throws IOException, ClassNotFoundException {

        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);

        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);
        TestYuanXing o = (TestYuanXing)objectInputStream.readObject();
        objectInputStream.close();
        byteArrayInputStream.close();
        objectOutputStream.close();
        byteArrayOutputStream.close();

        return o;

    }

}
